package com.app;

import com.app.factories.SymbolFactory;

import android.app.Activity;
import android.content.Context;
import android.inputmethodservice.KeyboardView.OnKeyboardActionListener;
import android.text.Editable;
import android.view.View;
import android.widget.EditText;

public class KeyboardListener implements OnKeyboardActionListener {
	Activity activity;

	public KeyboardListener(Activity activity) {
		this.activity = activity;
	}

	@Override
	public void onKey(int primaryCode, int[] keyCodes) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onPress(int primaryCode) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onRelease(int primaryCode) {
		View focusedView = activity.getCurrentFocus();

		if (focusedView instanceof GraphEdit) {
			
			Editable text;
			String text1 = "";
			GraphEdit e = (GraphEdit) focusedView;

			if (primaryCode == 40) {
				text = e.getText();

				if (text.length() > 0) {
					e.setText(text.toString().substring(0, text.length() - 1));
					e.setCursotPosition();
					return;
				}

			} else if (primaryCode > 9) {
				text1 = SymbolFactory.getSymbol(primaryCode);

			} else {
				text1 = Integer.toString(primaryCode);
			}

			e.append(text1);

		}

	}

	@Override
	public void onText(CharSequence text) {
		// TODO Auto-generated method stub

	}

	@Override
	public void swipeDown() {
		// TODO Auto-generated method stub

	}

	@Override
	public void swipeLeft() {
		// TODO Auto-generated method stub

	}

	@Override
	public void swipeRight() {
		// TODO Auto-generated method stub

	}

	@Override
	public void swipeUp() {
		// TODO Auto-generated method stub

	}

}
